import { Command, logger, ModeOptions, createServer } from "f2e-server3"
import TailwindPlugin from "@tailwindcss/postcss"

const app = new Command()
    .option('-m, --mode <mode>', 'server mode: dev, build or prod', 'dev', ModeOptions)
    .action(async (options) => {
        const { mode } = options
        logger.setLevel('DEBUG')
        createServer({
            mode,
            gzip: true,
            buildFilter: pathname => /^(index|$)/.test(pathname),
            watchFilter: pathname => /^(index|src|$)/.test(pathname),
            outputFilter: pathname => /^(index|static|$)/.test(pathname),
            try_files: 'index.html',
            postcss: {
                entryPoints: {
                    in: 'src/main.css',
                    out: 'static/main.css',
                },
                plugins: [
                    TailwindPlugin({
                        optimize: mode === 'build',
                    }),
                ],
            },
            proxies: [
                {
                    location: "/api/chat",
                    origin: "http://localhost:11434",
                    requestHeaders: () => {
                        return {
                            'Content-Type': 'application/json', 
                        } 
                    },
                    stream: true,
                    pathname: "/api/chat",
                }
            ],
            dest: 'ollama_chat',
        })
    })

app.parse(process.argv)